package edu.whut.mall.admin.controller;

import edu.whut.mall.admin.service.IProductSellService;
import edu.whut.mall.common.api.ResponseMap;
import edu.whut.mall.common.vo.ProductSellVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;


/**
 * Author: smq
 * Unit: D9lab
 * Date: 2021-06-07 16:15
 */
@Api(tags = {"销售商品"}, description = "商品管理", produces = MediaType.APPLICATION_JSON_VALUE)
@RestController
@RequiredArgsConstructor
@RequestMapping("/product")
public class ProductSellController {


    private final IProductSellService productSellService;


    @ApiOperation(value = "获取单个商品信息", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "productId", value = "产品id", paramType = "form", dataType = "int", required = true)
    })
    @RequestMapping(value = "/getProductSell", method = RequestMethod.POST)
    public Map<String,Object> getProductSell(HttpServletRequest request, int productId) throws Exception {
        ResponseMap map = ResponseMap.getInstance();
        ProductSellVo product = productSellService.getProductSell(productId);
        if (product == null) {
            return map.putFailure("获取失败", 0);
        }
        return map.putValue(product, "获取成功");
    }
}
